package main

import (
	"fmt"
	"sync"
	"time"
)
//使用原子计数记录被执行的次数。使用Mutex Lock Unlock锁定被执行函数，防止被重复执行
func main() {
	o := &sync.Once{}
	go do(o)
	go do(o)
	time.Sleep(time.Second * 2)

}

func do(o *sync.Once) {
	fmt.Println("Start do")
	o.Do(func() {
		fmt.Println("Doing something...")
	})

	fmt.Println("Do end")
}
